<?php
/**
 * Created by PhpStorm.
 * User: stc17
 * Date: 2020/3/5
 * Time: 11:16
 */

namespace App\Listener;

use SwoStar\Event\Listener;
use SwoStar\Server\Server;

class StartListener extends Listener
{
    protected $name='start';

   public function handler(Server $server=null)
   {
       $config = $this->app->make('config');
       dd('this is startlinster handler','startlinster');
       go(function()use($server,$config){
        $cli = new \Swoole\Coroutine\Http\Client($config->get('server.route.server.host'),
            $config->get('server.route.server.port'));
        $ret = $cli->upgrade("/"); //升级的websockt

        $data=[
            'ip'        =>$config->get('server.ws.host'),
            'port'      =>$config->get('server.ws.port'),
            'ServerName'=>'swostar_im1',
            'method'    =>'register',
        ];
        $cli->push(json_encode($data));
        //维持心跳检测
        swoole_timer_tick(3000,function()use($cli){
           $cli->push('',WEBSOCKET_OPCODE_PING);
        });
       // $cli->close();
        });

   }
}